//
//  TravelAreaCollectionViewCell.m
//  ToWhere
//
//  Created by dllo on 15/11/13.
//  Copyright © 2015年 www.TE.com. All rights reserved.
//

#import "TravelAreaCollectionViewCell.h"
#import <SDWebImageManager.h>
#import <UIImageView+WebCache.h>

@interface TravelAreaCollectionViewCell ()
//照片
@property (nonatomic, retain) UIImageView *imagePic;
//中文地名Label
@property (nonatomic, retain) UILabel *ChineseLabel;
//英文地名Label
@property (nonatomic, retain) UILabel *EnglishLabel;
//背景View
@property (nonatomic, retain) UIView *view;
//旅行地个数label
@property (nonatomic, retain) UILabel *numberLabel;

@end


@implementation TravelAreaCollectionViewCell

-(void)dealloc
{
    [_imagePic release];
    [_ChineseLabel release];
    [_EnglishLabel release];
    [_view release];
    [_numberLabel release];
    [_areaModel release];
    [super dealloc];
}
#pragma mark 初始化
-(instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        
        [self createView];
    }
    return self;
}
#pragma mark 创建视图
-(void)createView
{
    self.imagePic =[[UIImageView alloc]init];
  //  self.imagePic.backgroundColor = [UIColor redColor];
    [self addSubview: self.imagePic];
    [_imagePic release];
    
    self.ChineseLabel = [[UILabel alloc]init];
   // self.ChineseLabel.backgroundColor = [UIColor yellowColor];
    self.ChineseLabel.font = [UIFont systemFontOfSize:17 *kWidth];
    self.ChineseLabel.textColor = [UIColor whiteColor];

    [self.imagePic addSubview: self.ChineseLabel];
    [_ChineseLabel release];
    
    self.EnglishLabel = [[UILabel alloc]init];
   // self.EnglishLabel.backgroundColor = [UIColor greenColor];
     self.EnglishLabel.textColor = [UIColor whiteColor];
    self.EnglishLabel.font = [UIFont systemFontOfSize:15 *kWidth];
    [self.imagePic addSubview: self.EnglishLabel];
    [_EnglishLabel release];
    
    
    self.numberLabel = [[UILabel alloc]init];
    self.numberLabel.backgroundColor = [[UIColor blackColor]colorWithAlphaComponent:0.2];
    self.numberLabel.layer.borderColor = [UIColor lightGrayColor].CGColor;
    self.numberLabel.layer.masksToBounds = YES;
    self.numberLabel.layer.borderWidth = 1;
    self.numberLabel.layer.cornerRadius = 15 *kWidth;
    self.numberLabel.textAlignment = NSTextAlignmentCenter;
     self.numberLabel.textColor = [UIColor whiteColor];
    [self addSubview: self.numberLabel];
    [_numberLabel release];
    
}

#pragma mark 计算尺寸
-(void)layoutSubviews
{
    [super layoutSubviews];
    
    self.imagePic.frame = CGRectMake(0, 0, self.frame.size.width, self.frame.size.height);
    
    self.ChineseLabel.frame = CGRectMake(5 * kWidth, 5 * kHeight, self.imagePic.frame.size.width - 10 * kWidth, 25 * kHeight);
    
    self.EnglishLabel.frame = CGRectMake(self.ChineseLabel.frame.origin.x, self.ChineseLabel.frame.size.height + self.ChineseLabel.frame.origin.y, self.ChineseLabel.frame.size.width, self.ChineseLabel.frame.size.height);
    
    self.view.frame = CGRectMake(20 * kHeight, self.imagePic.frame.size.height  - 40 * kHeight, self.imagePic.frame.size.width - 40 * kWidth, 30* kHeight);
    
    self.numberLabel.frame = CGRectMake(25 * kHeight, self.imagePic.frame.size.height  - 40 * kHeight, self.imagePic.frame.size.width - 50 * kWidth, 28 *kHeight);

}

-(void)setAreaModel:(TraveAreaModel *)areaModel
{
    if (_areaModel != areaModel) {
        [_areaModel release];
        _areaModel = [areaModel retain];
    }

   [self.imagePic sd_setImageWithURL:[NSURL URLWithString:areaModel.image_url] placeholderImage:[UIImage imageNamed:@"Travel_place"]];
    
    self.ChineseLabel.text = areaModel.name_zh_cn;
    self.EnglishLabel.text = areaModel.name_en;
    self.numberLabel.text = [NSString stringWithFormat:@"旅游地%@",areaModel.poi_count];
    
    
}



/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

@end
